import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "../store/store";

Vue.use(VueRouter)

const routes = [
    {
        path: '/:chapters(login)+',
        name: '登陆页',
        hidden: true,
        component: () => import('../components/LoginView')
    },
    {
        path: '/home',
        name: '首页',
        code: "home",
        iconClass: "fa fa-home",
        component: () => import('../components/HomeView')
    },
    {
        path: '/sys',
        name: '系统管理',
        code: "system",
        iconClass: "fa fa-gear",
        component: () => import('../components/HomeView'),
        children: [
            {
                path: '/sys/user/manager',
                name: '用户管理',
                code: "user",
                component: () => import('@/components/sys/UserManager')
            },
            {
                path: '/home/role/manager',
                name: '角色管理',
                code: "role",
                component: () => import('@/components/sys/RoleManager')
            },
            {
                path: '/data/view',
                name: '数据概览',
                code: "home",
                hidden: true,
                component: () => import('../components/DataOverview')
            },
            {
                path: '/sys/operate/log',
                name: '操作日志',
                code: "operateLog",
                component: () => import('@/components/sys/OperateLog')
            },
            {
                path: '/sys/organization/manager',
                name: '组织架构',
                code: "organization",
                component: () => import('@/components/sys/OrganizationManager')
            }
        ]
    },
    {
        path: "/workflow",
        name: "工作流管理",
        code: "workflow",
        iconClass: "fa fa-gears",
        component: () => import('../components/HomeView'),
        children: [
            {
                path: '/workflow/process/definition/manager',
                name: '工作流模版管理',
                code: "processDefinition",
                component: () => import('@/components/workflow/ProcessDefinitionManager')
            },
            {
                path: '/workflow/process/instance/manager',
                name: '工作流实例管理',
                code: "processInstance",
                component: () => import('@/components/workflow/ProcessInstanceManager')
            },
            {
                path: '/workflow/process/history/instance/manager',
                name: '历史工作流实例管理',
                code: "historyProcessInstance",
                component: () => import('@/components/workflow/HistoryProcessInstanceManager')
            }
        ]
    },
    {
        path: '*',
        name: '404',
        hidden: true,
        component: () => import('../components/NotFound')
    }
]


const router = new VueRouter({
    routes,
    mode: 'history'
})


router.beforeEach((to, from, next) => {
    if (!store.state.user) {
        if (to.path !== '/login') {
            next('/login')
        } else {
            next()
        }
    }
    next()
})


export default router
